#include <stdio.h>

int value(char *p){
    int a;
    switch ( *p ){
            case 'I':a=1;break;
            case 'V':a=5;break;
            case 'X':a=10;break;
            case 'L':a=50;break;
            case 'C':a=100;break;
            case 'D':a=500;break;
            case 'M':a=1000;break;
        }
    return a;
}

int romanToInt(char * s){
    char *p = s;
    int ret=0;
    int t=1;
    
    do{
        if ( (t=value(p)) < (value(p+1)) ){
            t*=-1;
        }
        ret += t;
    }while ( *(p+1) && p++ );
    return ret;
}

int main(){
	printf("%d", romanToInt("III"));
	return 0;	
}
